<?php

require_once 'Zend/View/Helper/Abstract.php';

class Core_View_Helper_Admin_SelectDesign extends Zend_View_Helper_Abstract
{
    /**
     *
     */
    public function selectDesign($name, $value = null, $attribs = null, $options = null)
    {
        $templateConfig = Zend_Registry::get('config')->template;
        $templates = Core_Filesystem_Dir::getDirectories(BASE_PATH . '/' . $templateConfig->pathToTemplates . '/public');
        foreach ($templates as $template) {
            $designs = Core_Filesystem_File::getFilesByType(BASE_PATH . '/' . $templateConfig->pathToTemplates . '/public/' . $template . '/pages', 'xml');
            if (is_array($designs)) {
                foreach ($designs as $design) {
                    $design = Core_Toolbox_Regex::stripFileExtension($design);
                    $options[$template . '_' . $design] = $template . ' / ' . $design;
                }
            }
        }
        $form   = new Core_Form();
        $select = $form->createElement('select', $name, array(
            'multiOptions'  => $options,
            'value'         => $value,
        ));
        if (is_array($attribs)) {
            $select->setAttribs($attribs);
        }
        return $select;
    }
}